import { takeEvery, put } from "redux-saga/effects";
import { GETINITLIST } from "./actiontypes";
import { initListAction } from "./actionCreater";
import axios from "axios";
function* getInitList() {
    try{
        console.log("saga接收到组件派发的action");
  const res = yield axios.get("/api/todolist.json");
  const action = initListAction(res.data.data);
  //   相当于store.dispatch(action)
  yield put(action);
    } catch(e){
        console.log('请求数据失败')
    }
  
}

// generator函数
function* mySaga() {
    // 接收到组件派发的actiontype
  yield takeEvery(GETINITLIST, getInitList);
}
export default mySaga;
